<?php
    $apartamente    = $consumuriApartamente['apartamente'];
    $consumuri      = $consumuriApartamente['consumuri'];

    $blocIDs = array();
    $scaraIDs = array();

    /* @var $form ConsumuriForm */
?>

<form id="add-consumuri-form" name="<?php echo strtolower($form->getName()) ?>" request="<?php echo url_for($form->request)?>" action="javascript:void(0)" autocomplete="off">

    <?php echo $form->renderHiddenFields(); ?>

    <div class="action-buttons">
        <input type="submit" value="înregistrează/corectează consumurile" />
    </div>

    <div class="error-container"></div>

    <div class="blocuri-tabs">
        <ul>
            <?php foreach ($apartamente as $bloc => $blocData): ?>
            <li>
                <a href="#<?php echo $blocIDs[$bloc] = $bloc.'-'.time() ?>"><?php echo $bloc ?></a>
            </li>
            <?php endforeach; ?>
        </ul>

        <?php foreach ($apartamente as $bloc => $blocData): ?>
        <div id="<?php echo $blocIDs[$bloc] ?>">

            <div class="scari-tabs">
                <ul>
                    <?php foreach ($blocData as $scara => $scaraData): ?>
                    <li>
                        <a href="#<?php echo $scaraIDs[$scara] = $scara.'-'.time() ?>"><?php echo $scara ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>

                <?php foreach ($blocData as $scara => $scaraData): ?>
                <div id="<?php echo $scaraIDs[$scara] ?>">
                    <table class="consumuri">
                        <thead>
                            <tr>
                                <th>Etaj</th>
                                <th>Nr. ap.</th>
                                <th>Proprietar</th>
                            <?php foreach ($consumuri as $criteriuId => $denumire): ?>
                                <th><?php echo $denumire ?></th>
                            <?php endforeach; ?>
                            </tr>
                        </thead>

                        <tbody>
                            <?php foreach ($scaraData as $etaj => $etajData): ?>
                                <?php foreach ($etajData as $nrAp => $apData): ?>
                                <tr>
                                    <td class="etaj"><?php echo $etaj ?></td>
                                    <td class="nr-ap"><?php echo $nrAp ?></td>
                                    <td class="proprietar"><?php echo $apData['PROPRIETAR'] ?></td>
                                    <?php foreach ($consumuri as $criteriuId => $denumire): ?>
                                    <td class="consum">
                                        <input type="text" class="valoare-consum"
                                               name="<?php echo $form->getName() ?>[<?php echo $apData['APARTAMENT_ID'] ?>][<?php echo $criteriuId ?>]"
                                               value="<?php echo @$apData['CONSUMURI'][$criteriuId] ?>"
                                               data-orig-value="<?php echo @$apData['CONSUMURI'][$criteriuId] ?>"
                                               _important="1" />
                                    </td>
                                    <?php endforeach; ?>
                                </tr>
                                <?php endforeach; ?>
                            <?php endforeach; ?>
                        </tbody>

                    </table>
                </div>
                <?php endforeach; ?>

            </div>

        </div>
        <?php endforeach; ?>

    </div>

</form>
